<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">

    <script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layui-form-item">
        <form action="" class="layui-form" lay-filter="studentForm">
        <input type="hidden" name="p_id">
        <div class="layui-form-item">
        <label class="layui-form-label required">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="p_name" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入用户名"
                value="" class="layui-input">
            <!-- <tip>填写自己管理账号的名称。</tip> -->
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label required">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="p_sex" value="男" title="男" checked="">
            <input type="radio" name="p_sex" value="女" title="女">
        </div>
    </div>

    <!-- <div class="layui-form-item">
        <label class="layui-form-label">生日</label>
        <div class="layui-input-block">
            <input type="text" name="birthday" id="date" lay-verify="date" placeholder="yyyy-MM-dd"
                autocomplete="off" class="layui-input">
        </div>
    </div> -->

    <div class="layui-form-item">
        <label class="layui-form-label required">购房时间</label>
        <div class="layui-input-block">
            <input type="date" name="p_purchaseHouseTime" lay-verify="required" lay-reqtext="日期不能为空" placeholder="请输入手机"
                value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">付款方式</label>
        <div class="layui-input-block">
            <input type="radio" name="p_paymentMethod" value="全款" title="全款" checked="">
            <input type="radio" name="p_paymentMethod" value="分期" title="分期">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">购房价格</label>
        <div class="layui-input-block">
            <input type="text" name="p_housePice" placeholder="请输入金额单位为W" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">房号</label>
        <div class="layui-input-block">
            <input type="text" name="p_houseLocation" placeholder="请输入房号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">紧急联系人</label>
        <div class="layui-input-block">
            <input type="text" name="p_emergencyContact" placeholder="请输入紧急联系人手机号码或电话号码" value="" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
        </form>
</div>


    <script>
        
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
            var json=localStorage.getItem("informationRecord")
            var stuObj= JSON.parse(json)
            console.log(stuObj)
            $("img").attr("src",stuObj.i_pic)
            console.log(stuObj)
            //给表单项赋值
            form.val("studentForm",{
                p_id:stuObj.p_id,
                p_name:stuObj.p_name,
                p_sex:stuObj.p_sex,
                p_purchaseHouseTime:stuObj.p_purchaseHouseTime,
                p_paymentMethod:stuObj.p_paymentMethod,
                p_housePice:stuObj.p_housePice,
                p_houseLocation:stuObj.p_houseLocation,
                p_emergencyContact:stuObj.p_emergencyContact

            })
        })

        layui.use(['form', 'upload', 'element'], function () {
            var form = layui.form,
                layer = layui.layer,
                upload = layui.upload,
                element = layui.element,
                laydate = layui.laydate,
                $ = layui.$;

            // 渲染日期组件
            laydate.render({
                elem: '#date'
            });

        

                form.on('submit(saveBtn)', function (data) {
            //var index = layer.alert(JSON.stringify(data.field), {
             //   title: '最终的提交信息'
            //}, function () {
                // 关闭弹出层
                //layer.close(index);
           // });
            $.ajax({
                type:"get",
                url:"http://127.0.0.1:8080/purchasehouse/update",
                data:data.field,
              //  contentType:"json",
                success:function(res){
                    console.log(res)
                   if(res.code==0){
                       console.log(res.code)
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.msg("修改成功！",{time: 1000},
                function(){
                parent.layer.close(iframeIndex);
                parent.location.reload();
                })
                
            }else{
                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.msg("修改失败！",{time: 1000},
                function(){
                parent.layer.close(iframeIndex);
                parent.location.reload();
                })
            }
            },   
            })
           
            return false;
        });

        });
    </script>
</body>

</html>